﻿using Microsoft.AspNetCore.Mvc;
using NXDO.WebAPI.Controllers;
using System;
using System.IO;
using TDM.WebBase;
using TDM.WebBiz.TestData;

namespace TDM.WebSvr.Controllers.TestData
{
    public class DataExportUpDnldController : ApiBinaryController
    {
        protected override string GetSaveFileName(string name, bool nameIsMimeContentType)
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// 用于导出数据包的下载
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        protected override string GetDownloadFileName(string name)
        {
            var id = Convert.ToInt64(name);
            string basePath = BasePathHelper.GetDataExportPath();
            var dataImport = DataExportHelper.Get(id);
            if (dataImport == null) throw new Exception("下载的数据有误");
            string fullpath = Path.Combine(basePath, dataImport.FilePath);
            if (!System.IO.File.Exists(fullpath)) throw new Exception("未找到下载的文件");
            return fullpath;
        }
    }
}
